<?php
/**
 * Widget to handle ressource as a self api
 */
$xview = Xview::instance();
$search = $xview->val('search',false);

$wrapper = $xview->component('ressource', 'criteria');
$inputs = $wrapper->get();

$interviewed = $wrapper->item("hasbeenintv")->toInt();
$joins = null;
$jobInfo = false;

$filters[] = $wrapper->item("kn_number_year")->fragments();
if(!$wrapper->item("salary")->initial())
{
	$filters[] = $wrapper->item("salary")->fragments();
	$jobInfo = true;
}
if(!empty($inputs["status"]))
{
	$filters[] = $wrapper->item("status")->fragments();
}
if(!$wrapper->item("available_date")->initial())
{
	$jobInfo = true;
	$filters[] =  $wrapper->item("available_date")->fragments("end_date");
}
if($interviewed !== null)
{
	if($interviewed)
	{
		$joins[] = Hive\Ressource::$JOIN_INTERVIEWS;
		$filters[] = new Fox\Dao\SqlFragment("intv.loekz = ? ",array(0));
	}
	else
	{
		$joins[] = Hive\Ressource::$LEFTJOIN_INTERVIEWS;
		$filters[] = new Fox\Dao\SqlFragment("intv.iid IS NULL ");
	}
}
$filters = Fox\Dao\SqlFragment::combine($filters);